package com.cn.why.springcloudskills.util;

import org.apache.tomcat.jdbc.pool.DataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 远程连接数据库配置（数据库配置信息放在gitee上）
 */
@Configuration
public class DataSourceConfig {
    @Value("${url}")
    private String url;
    @Value("${driver}")
    private String driverClass;
    @Value("${username}")
    private String userName;
    @Value("${password}")
    private String password;
    //数据源类型
    @Value("${type}")
    private String type;
    @Bean
    //获取数据源x`x`
    public DataSource getDataSource(){
        //数据库连接池
        DataSource source = new DataSource();
        source.setUrl(url);
        source.setDriverClassName(driverClass);
        source.setUsername(userName);
        source.setPassword(password);
        source.setDataSourceJNDI(type);
        source.setMaxActive(20);
        return source;
    }
}